/**
 * 
 */
package pl.lodz.p.browarex.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import pl.lodz.p.browarex.dao.GenericDao;
import pl.lodz.p.browarex.model.Ingredient;
import pl.lodz.p.browarex.model.IngredientOrderInfo;


@Service
@Transactional(propagation = Propagation.REQUIRES_NEW)
@Qualifier("IngredientOrderInfoService")
public class IngredientOrderInfoService implements GenericService<IngredientOrderInfo, Long> {
	@Autowired
	private GenericDao<Ingredient, Long> ingredientDao;

	@Autowired
	@Qualifier("IngredientOrderInfoDao")
	private GenericDao<IngredientOrderInfo, Long> ingredientOrdetInfoDao;

	

	@Override
	public void upsert(IngredientOrderInfo object) {
//		IngredientOrderInfo persistedObjects = find(object.getId());
//		if (persistedObjects != null) {
////			Ingredient ingredient = persistedObjects.get(0);
////			ingredient.setAmount(object.getAmount());
////			ingredient.setName(object.getName());
////			ingredientOrdetInfoDao.update(ingredient);
//		} else {
			ingredientOrdetInfoDao.create(object);
//		}
	}

	

	@Override
	public void delete(IngredientOrderInfo object) {
		IngredientOrderInfo persistedObjects = find(object.getId());
		
			ingredientOrdetInfoDao.delete(persistedObjects);
	
	}

	

	@Override
	public IngredientOrderInfo find(Long id) {
		return ingredientOrdetInfoDao.findById(id);
	}

	

	@Override
	public List<IngredientOrderInfo> findByGuid(String guid) {
		return ingredientOrdetInfoDao.findAllByProperty("ingredientId", guid);
	}

	

	@Override
	public List<IngredientOrderInfo> list() {
		return ingredientOrdetInfoDao.findAll();
	}


	@Override
	public List<IngredientOrderInfo> findByProperty(String property, Object value) {
		return ingredientOrdetInfoDao.findAllByProperty(property, value);
	}

}
